<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of User
 *
 * @author Loug S
 */
class User extends Modele{
    //put your code here
    private $selectUser ;
    private $insertUser ;
	
	
    public function __construct(){
	parent::__construct();
	$sql = 'SELECT u.login, u.email
				FROM Users u
				ORDER BY email';
	$this->selectAll = Controller::$db->prepare($sql);
		
	$sql = 'SELECT u.email, u.login, u.password
				FROM Users u
				WHERE u.email = ?';
	$this->selectUser = Controller::$db->prepare($sql);	
	$sql = 'INSERT INTO 
		       Users
		VALUES (?,?,?)';
		$this->insertUser = Controller::$db->prepare($sql);
                
        $this->selectUser = Controller::$db->prepare($sql);	
	$sql = 'UPDATE Users
                SET ? = ? WHERE ? = ?' ; 
		$this->updateUser = Controller::$db->prepare($sql);
	}
	
	public function getUser($email) {
		$this->selectUser->execute(array($email));
		$row = $this->selectUser->fetchAll();
		if(empty($row[0])){
			return array();
		}
		else{
			return $row[0];
		}
	}
	
	
	public function saveUser($login,$email,$password) {
                if(count($this->getUser($email))==0) {
                  $this->insertUser->execute(array($login,$email,$password));
                  
                }
	}
        
        public function setUser($champ,$value, $old){

           $this->updateUser->execute(array($champ,$value, $old));
                
        }
        
        // save regroupe create et update
        public function save() {


        }

    public function delete() {
        
    }

    public function __get() {
         $this->selectAll->execute();
        
    }

    public function __set() {
        
    }

    public function __isset() {
        
    }

    public function __unset() {
        
    }

    public function query_columns() {
        
    }
}

?>
